using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace BB.Processes.Models.Mapping
{
    public class RegistoMap : EntityTypeConfiguration<Registo>
    {
        public RegistoMap()
        {
            // Primary Key
            this.HasKey(t => new { t.Id, t.Active });

            // Properties
            this.Property(t => t.Id)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            // Table & Column Mappings
            this.ToTable("Registoes");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.CompeticaoId).HasColumnName("CompeticaoId");
            this.Property(t => t.UserId).HasColumnName("UserId");
            this.Property(t => t.Active).HasColumnName("Active");

            // Relationships
            this.HasOptional(t => t.Competicao)
                .WithMany(t => t.Registoes)
                .HasForeignKey(d => d.CompeticaoId);
            this.HasOptional(t => t.UserProfile)
                .WithMany(t => t.Registoes)
                .HasForeignKey(d => d.UserId);

        }
    }
}
